/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PreferencesWindow.java
 *
 * Created on Apr 17, 2012, 5:56:09 PM
 */
package alwv;

import javax.swing.tree.TreePath;
import alwv.preferences.*;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;

/**
 *
 * @author Sam
 */
public class PreferencesWindow extends javax.swing.JDialog {
        private static MainView mainview;

    /** Creates new form PreferencesWindow */
    public PreferencesWindow(java.awt.Frame parent, boolean modal, MainView mv) {
        super(parent, modal);
        initComponents();
        mainview = mv;
        pChangeFontSizePane = new PreferencesChangeFontSizePane();
        pChangeGuestPasswordPane = new PreferencesChangeGuestPasswordPane();
        pChangeTreasurerPasswordPane = new PreferencesChangeTreasurerPasswordPane();
        pDBBackupFrequencyPane = new PreferencesDBBackupFrequencyPane();
        pDBBackupLocationPane = new PreferencesDBBackupLocationPane();
        pEditPermissionsPane = new PreferencesEditPermissionsPane();
        pDBBackupRevertPane = new PreferencesDBBackupRevertPane(mv);
        pDBBackupCreateNowPane = new PreferencesDBBackupCreateNowPane();
        this.setTitle("Preferences");
        preferencesTree.getSelectionModel().setSelectionMode(javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        preferencesTree = new javax.swing.JTree();
        PreferencesContentPane = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Accounts");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Change Treasurer Password");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Change Guest Password");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Database Backups");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Revert");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Create Now");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        preferencesTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        preferencesTree.setName("preferencesTree"); // NOI18N
        preferencesTree.setRootVisible(false);
        preferencesTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                preferencesTreeValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(preferencesTree);

        PreferencesContentPane.setName("PreferencesContentPane"); // NOI18N

        javax.swing.GroupLayout PreferencesContentPaneLayout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(PreferencesContentPaneLayout);
        PreferencesContentPaneLayout.setHorizontalGroup(
            PreferencesContentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 484, Short.MAX_VALUE)
        );
        PreferencesContentPaneLayout.setVerticalGroup(
            PreferencesContentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 511, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PreferencesContentPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE)
            .addComponent(PreferencesContentPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void preferencesTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_preferencesTreeValueChanged
    TreePath a = evt.getPath();
    Object[] data = a.getPath();
    String thisSelection = data[data.length-1].toString();
    PreferencesContentPane.removeAll();
    if (thisSelection.equals("Edit Permissions")) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pEditPermissionsPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pEditPermissionsPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        
    }
    else if (thisSelection.equals("Change Treasurer Password")) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pChangeTreasurerPasswordPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pChangeTreasurerPasswordPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
    else if (thisSelection.equals("Change Guest Password")) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pChangeGuestPasswordPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pChangeGuestPasswordPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
    else if (thisSelection.equals("Set Font Size")) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pChangeFontSizePane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pChangeFontSizePane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
    else if (thisSelection.equals("Frequency")) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pDBBackupFrequencyPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pDBBackupFrequencyPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
    else if (thisSelection.equals("Directory")) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pDBBackupLocationPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pDBBackupLocationPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
    else if (thisSelection.equals("Revert")) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pDBBackupRevertPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pDBBackupRevertPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
    else if (thisSelection.equals("Create Now")) {
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(PreferencesContentPane);
        PreferencesContentPane.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pDBBackupCreateNowPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pDBBackupCreateNowPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
}//GEN-LAST:event_preferencesTreeValueChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PreferencesWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PreferencesWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PreferencesWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PreferencesWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                PreferencesWindow dialog = new PreferencesWindow(new javax.swing.JFrame(), true, mainview);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PreferencesContentPane;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTree preferencesTree;
    // End of variables declaration//GEN-END:variables
    private PreferencesChangeFontSizePane pChangeFontSizePane;
    private PreferencesChangeGuestPasswordPane pChangeGuestPasswordPane;
    private PreferencesChangeTreasurerPasswordPane pChangeTreasurerPasswordPane;
    private PreferencesDBBackupFrequencyPane pDBBackupFrequencyPane;
    private PreferencesDBBackupLocationPane pDBBackupLocationPane;
    private PreferencesEditPermissionsPane pEditPermissionsPane;
    private PreferencesDBBackupRevertPane pDBBackupRevertPane;
    private PreferencesDBBackupCreateNowPane pDBBackupCreateNowPane;
    
    
}
